<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tomcat 多应用隔离架构指南</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        /* 首字下沉效果 */
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.5rem;
            font-weight: 700;
            color: #4a5568;
            font-family: 'Noto Serif SC', serif;
        }
        
        /* 代码块美化 */
        pre {
            background: #1e293b;
            color: #e2e8f0;
            border-radius: 12px;
            padding: 1.5rem;
            overflow-x: auto;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            position: relative;
            margin: 2rem 0;
        }
        
        pre::before {
            content: attr(data-language);
            position: absolute;
            top: 0.5rem;
            right: 1rem;
            font-size: 0.75rem;
            color: #64748b;
            text-transform: uppercase;
            letter-spacing: 0.1em;
        }
        
        /* 卡片悬停效果 */
        .feature-card {
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }
        
        .feature-card:hover {
            transform: translateY(-8px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
        }
        
        /* 标题装饰线 */
        .section-title::after {
            content: '';
            display: block;
            width: 60px;
            height: 4px;
            background: linear-gradient(90deg, #3b82f6 0%, #8b5cf6 100%);
            margin-top: 1rem;
            border-radius: 2px;
        }
        
        /* 引用样式 */
        .quote-box {
            border-left: 4px solid #3b82f6;
            background: rgba(59, 130, 246, 0.05);
            padding: 1.5rem 2rem;
            margin: 2rem 0;
            border-radius: 0 8px 8px 0;
            position: relative;
        }
        
        .quote-box::before {
            content: '\f10d';
            font-family: 'Font Awesome 6 Free';
            font-weight: 900;
            position: absolute;
            top: -10px;
            left: 20px;
            font-size: 2rem;
            color: #3b82f6;
            opacity: 0.2;
        }
        
        /* 列表美化 */
        .custom-list li {
            position: relative;
            padding-left: 2rem;
            margin-bottom: 1rem;
        }
        
        .custom-list li::before {
            content: '\f00c';
            font-family: 'Font Awesome 6 Free';
            font-weight: 900;
            position: absolute;
            left: 0;
            color: #10b981;
        }
        
        /* 渐变按钮 */
        .gradient-btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            transition: all 0.3s ease;
        }
        
        .gradient-btn:hover {
            transform: scale(1.05);
            box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
        }
        
        /* Mermaid 图表样式 */
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            margin: 2rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero 区域 -->
    <section class="relative overflow-hidden bg-gradient-to-br from-blue-600 via-purple-600 to-pink-500 text-white">
        <div class="absolute inset-0 bg-black opacity-20"></div>
        <div class="relative container mx-auto px-6 py-24">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-7xl font-bold mb-6 leading-tight">
                    Tomcat 多应用隔离
                    <span class="block text-3xl md:text-4xl mt-4 font-light opacity-90">架构设计与实践指南</span>
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90 leading-relaxed">
                    构建安全、稳定、高效的企业级 Java 应用部署架构
                </p>
                <div class="flex justify-center space-x-6 text-sm">
                    <span class="flex items-center"><i class="fas fa-clock mr-2"></i> 15 分钟阅读</span>
                    <span class="flex items-center"><i class="fas fa-layer-group mr-2"></i> 架构设计</span>
                    <span class="flex items-center"><i class="fas fa-shield-alt mr-2"></i> 安全隔离</span>
                </div>
            </div>
        </div>
        <div class="absolute bottom-0 left-0 right-0">
            <svg viewBox="0 0 1440 120" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M0 120L60 105C120 90 240 60 360 45C480 30 600 30 720 37.5C840 45 960 60 1080 67.5C1200 75 1320 75 1380 75L1440 75V120H1380C1320 120 1200 120 1080 120C960 120 840 120 720 120C600 120 480 120 360 120C240 120 120 120 60 120H0Z" fill="white"/>
            </svg>
        </div>
    </section>

    <!-- 主要内容区 -->
    <main class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- 引言 -->
        <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12 mb-12">
            <p class="text-lg text-gray-700 leading-relaxed drop-cap">
                在 Tomcat 中实现多应用隔离是为了确保不同的应用不会相互干扰，提高系统的安全性和稳定性。Tomcat 提供了多种机制来实现应用和实例之间的隔离。本指南将深入探讨各种隔离策略，帮助您构建更加健壮的应用部署架构。
            </p>
        </div>

        <!-- 架构概览图 -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold text-gray-800 mb-6 section-title">隔离架构概览</h2>
            <div class="mermaid">
                graph TB
                    A[Tomcat 多应用隔离] --> B[应用级别隔离]
                    A --> C[虚拟主机隔离]
                    A --> D[实例级别隔离]
                    
                    B --> B1[独立 Context]
                    B --> B2[ClassLoader 隔离]
                    
                    C --> C1[Virtual Hosts]
                    C --> C2[域名隔离]
                    
                    D --> D1[多实例部署]
                    D --> D2[Docker 容器化]
                    
                    style A fill:#3b82f6,stroke:#1e40af,stroke-width:3px,color:#fff
                    style B fill:#10b981,stroke:#059669,stroke-width:2px,color:#fff
                    style C fill:#8b5cf6,stroke:#6d28d9,stroke-width:2px,color:#fff
                    style D fill:#f59e0b,stroke:#d97706,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- 应用级别隔离 -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold text-gray-800 mb-8 flex items-center">
                <i class="fas fa-cube text-blue-500 mr-4"></i>
                1. 应用级别的隔离
            </h2>

            <div class="grid md:grid-cols-2 gap-8">
                <!-- 独立 Context 配置 -->
                <div class="feature-card bg-white rounded-xl shadow-lg p-8">
                    <h3 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                        <i class="fas fa-cog text-green-500 mr-3"></i>
                        1.1 使用独立的 Context
                    </h3>
                    <p class="text-gray-600 mb-6 leading-relaxed">
                        Tomcat 的 <code class="bg-gray-100 px-2 py-1 rounded text-sm">Context</code> 元素代表一个 Web 应用。每个 Web 应用都可以在配置文件中定义独立的上下文，实现应用间的基础隔离。
                    </p>
                    
                    <div class="quote-box">
                        <p class="text-gray-700">
                            <strong>最佳实践：</strong>为每个应用配置独立的 Context，避免应用间的相互影响。
                        </p>
                    </div>

                    <h4 class="font-semibold text-gray-700 mb-3 mt-6">配置示例</h4>
                    <pre data-language="xml"><code>&lt;Context path="/app1" docBase="/path/to/app1" /&gt;
&lt;Context path="/app2" docBase="/path/to/app2" /&gt;</code></pre>

                    <div class="bg-blue-50 rounded-lg p-4 mt-6">
                        <h5 class="font-semibold text-blue-800 mb-2">配置参数说明</h5>
                        <ul class="custom-list text-gray-700">
                            <li><code class="bg-white px-2 py-1 rounded text-sm">path</code>：应用的访问路径</li>
                            <li><code class="bg-white px-2 py-1 rounded text-sm">docBase</code>：应用的实际部署路径</li>
                        </ul>
                    </div>
                </div>

                <!-- ClassLoader 配置 -->
                <div class="feature-card bg-white rounded-xl shadow-lg p-8">
                    <h3 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                        <i class="fas fa-layer-group text-purple-500 mr-3"></i>
                        1.2 配置 Web 应用的 ClassLoader
                    </h3>
                    <p class="text-gray-600 mb-6 leading-relaxed">
                        Tomcat 提供了灵活的 ClassLoader 配置机制，允许为不同的 Web 应用配置独立的类加载器，实现类级别的完全隔离。
                    </p>

                    <div class="quote-box">
                        <p class="text-gray-700">
                            <strong>核心优势：</strong>避免不同应用间的类冲突，提高系统稳定性。
                        </p>
                    </div>

                    <h4 class="font-semibold text-gray-700 mb-3 mt-6">配置示例</h4>
                    <pre data-language="xml"><code>&lt;Context&gt;
    &lt;Loader className="org.apache.catalina.loader.WebappLoader" 
            delegate="false"/&gt;
&lt;/Context&gt;</code></pre>

                    <div class="bg-purple-50 rounded-lg p-4 mt-6">
                        <h5 class="font-semibold text-purple-800 mb-2">关键配置解析</h5>
                        <p class="text-gray-700">
                            <code class="bg-white px-2 py-1 rounded text-sm">delegate="false"</code> 表示优先使用应用自己的类加载器，而不是父加载器，确保类的独立性。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- 虚拟主机隔离 -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold text-gray-800 mb-8 flex items-center">
                <i class="fas fa-server text-purple-500 mr-4"></i>
                2. 虚拟主机级别的隔离
            </h2>

            <div class="bg-white rounded-xl shadow-lg p-8">
                <h3 class="text-2xl font-semibold text-gray-800 mb-6 flex items-center">
                    <i class="fas fa-globe text-indigo-500 mr-3"></i>
                    2.1 使用虚拟主机（Virtual Hosts）
                </h3>
                
                <p class="text-gray-600 mb-6 leading-relaxed">
                    通过配置多个虚拟主机